package com.fzn3.day04;


import org.junit.Test;
import org.junit.jupiter.api.DisplayName;

import static com.fzn3.day04.BinarySearch.search;
import static org.junit.Assert.assertEquals;

/**
 * @program: DataStructure
 * @author: fzn
 * 描述：测试二分查找
 * @create: 2023/3/3 15:38
 **/
public class TestBinarySearch {

    @Test
    @DisplayName("找到")
    public void test1() {
        int[] arr = {7, 13, 21, 30, 38, 44, 52, 53};
        assertEquals(0, search(arr, 7));
        assertEquals(1, search(arr, 13));
        assertEquals(2, search(arr, 21));
        assertEquals(3, search(arr, 30));
        assertEquals(4, search(arr, 38));
        assertEquals(5, search(arr, 44));
        assertEquals(6, search(arr, 52));
        assertEquals(7, search(arr, 53));
    }

    @Test
    @DisplayName("没找到")
    public void test2() {
        int[] arr = {7, 13, 21, 30, 38, 44, 52, 53};
        assertEquals(-1, search(arr, 0));
        assertEquals(-1, search(arr, 15));
        assertEquals(-1, search(arr, 60));
    }
}
